
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
{
    // Start is called before the first frame update
    public GameObject energy;
    public GameObject enemyPrefab;
    public int enemyNum = 1;
    void Start()
    {
        SpawnEnemy(enemyNum);
    }

    // Update is called once per frame
    void Update()
    {
        if( GameObject.FindGameObjectsWithTag("Enemy").Length == 0)
        {

            SpawnEnemy(++enemyNum);
            SpawnEnergy();
        }
    }

    void SpawnEnemy(int num)
    {
        for(int i = 0; i < num; i++) 
        {
            Instantiate(enemyPrefab, GetRandomPos(), transform.rotation);
        }
    }

    void SpawnEnergy()
    {
        Instantiate(energy, GetRandomPos(), transform.rotation);
    }

    Vector3 GetRandomPos()
    {
        return new Vector3(Random.Range(-8f, 8f), 0, Random.Range(-8f, 8f));
    }
}
